﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UM_SERVER.Packet.InPacket
{
    /// <summary>
    ///     删除用户分组包
    /// </summary>
    class DeleteItemPacket : BaseInPackage
    {
        public DeleteItemPacket(InPackage inpackage) : base(inpackage)
        {
            
        }

        public override void InitPackage()
        {
            int Offset = 0;
            //用户名长度
            byte[] UsernameLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, UsernameLength, 0, 4);
            Offset += 4;
            //读取用户名
            byte[] Username = new byte[BitConverter.ToInt32(UsernameLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Username, 0, Username.Length);
            Offset += Username.Length;
            //分组ID
            byte[] ItemId = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, ItemId, 0, 4);
            Offset += 6;
            //IP地址长度
            byte[] IPLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, IPLength, 0, 4);
            Offset += 4;
            //IP地址
            byte[] IPAddress = new byte[BitConverter.ToInt32(IPLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, IPAddress, 0, IPAddress.Length);
            Offset += IPAddress.Length;
            //聊天端口
            byte[] Talkport = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Talkport, 0, 4);

            this.DIC_CONTENT.Add("USERNAME", Username);
            this.DIC_CONTENT.Add("ITEMID", ItemId);
            this.DIC_CONTENT.Add("IPADDRESS", IPAddress);
            this.DIC_CONTENT.Add("TALKPORT", Talkport);
        }

        /// <summary>
        ///     等到分组ID
        /// </summary>
        /// <returns>返回分组ID</returns>
        public int GetItemId()
        {
            return BitConverter.ToInt32(this.DIC_CONTENT["ITEMID"], 0);
        }
    }
}
